package com.pos.clothes.controller;

import com.pos.clothes.pojo.Clothes;
import com.pos.clothes.service.ClothesService;
import com.pos.clothes.util.JsonData;
import com.pos.clothes.util.ValidFlag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequiresPermissions("3")
public class ClothesController {
    @Autowired
    private ClothesService service;
    @Autowired
    private Clothes clothes;
    @RequestMapping(value = "/insertClothes",method = RequestMethod.POST)
    @ResponseBody
    public Object insertClothes(@RequestParam("name") String name,
                                 @RequestParam("idcategory") Integer idcategory){
        String flag = ValidFlag.getValidFlag(idcategory);
        clothes.setFlag(flag);
        clothes.setName(name);
        clothes.setIdcategory(idcategory);
        int res = service.insertClothes(clothes);
//        if (res!=0){
//            return JsonData.buildSuccess(res,"规格插入成功");
//        }else{
//            return JsonData.buildError("插入失败");
//        }
        return res;
    }
}
